package com.situ.blog.service.impl;



import com.situ.blog.dao.ITypeDao;
import com.situ.blog.dao.impl.TypeDaoImpl;
import com.situ.blog.pojo.Type;
import com.situ.blog.pojo.query.TypeQuery;
import com.situ.blog.service.ITypeService;
import com.situ.blog.util.PageResult;

import java.util.List;

public class TypeServiceImpl implements ITypeService {
    private ITypeDao typeDao = new TypeDaoImpl();

    @Override
    public List<Type> selectAll() {
        return typeDao.selectAll();
    }

    @Override
    public PageResult selectByPage(TypeQuery typeQuery) {
        List<Type> list = typeDao.selectByPage(typeQuery);
        int totalCount = typeDao.selectTotalCount(typeQuery);

        PageResult<Type> pageResult = new PageResult<>(0, "", totalCount, list);
        return pageResult;
    }

    @Override
    public void deleteById(int id) {
        typeDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        //delete from type where id in(2,3)
        for (String id : ids) {
            typeDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Type type) {
        typeDao.add(type);
    }

    @Override
    public Type selectById(int id) {
        return typeDao.selectById(id);
    }

    @Override
    public void update(Type type) {
        typeDao.update(type);
    }
}
